const Controller = require('egg').Controller;

class HomeController extends Controller {
  /// 获取审核列表数据
  async getAudit() {
    const { ctx, app } = this
    const data = await ctx.service.page.getAudit()
    if (typeof data == 'string') {
      ctx.body = {
        code: -1,
        message: data
      }
    } else {
      ctx.body = {
        code: 1,
        data
      }
    }
  }

  /// 编辑审核列表数据
  async editAudit() {
    const { ctx, app } = this
    const data = await ctx.service.page.editAudit()
    if (typeof data == 'string') {
      ctx.body = {
        code: -1,
        message: data
      }
    } else {
      ctx.body = {
        code: 1,
        data
      }
    }
  }

  /// 判断订单列表数据
  async switchOrder() {
    const { ctx, app } = this
    const data = await ctx.service.page.switchOrder()
    if (typeof data == 'string') {
      ctx.body = {
        code: -1,
        message: data
      }
    } else {
      ctx.body = {
        code: 1,
        data
      }
    }
  }

  /// 判断审核列表数据
  async switchAudit() {
    const { ctx, app } = this
    const data = await ctx.service.page.switchAudit()
    if (typeof data == 'string') {
      ctx.body = {
        code: -1,
        message: data
      }
    } else {
      ctx.body = {
        code: 1,
        data
      }
    }
  }

    /// 判断团购列表数据
    async switchGrop() {
      const { ctx, app } = this
      const data = await ctx.service.page.switchGrop()
      if (typeof data == 'string') {
        ctx.body = {
          code: -1,
          message: data
        }
      } else {
        ctx.body = {
          code: 1,
          data
        }
      }
    }

  /// 获取订单列表数据
  async getOrder() {
    const { ctx, app } = this
    const data = await ctx.service.page.getOrder()
    if (typeof data == 'string') {
      ctx.body = {
        code: -1,
        message: data
      }
    } else {
      ctx.body = {
        code: 1,
        data
      }
    }
  }

   /// 删除团购数据
   async delAudit() {
    const { ctx, app } = this;
    const data = await ctx.service.page.delAudit()
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 1,
        message: '删除成功'
      }
    } else {
      ctx.body = {
        code: -1,
        message: '删除失败'
      }
    }
  }

   /// 删除订单数据
   async delOrder() {
    const { ctx, app } = this;
    const data = await ctx.service.page.delOrder()
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 1,
        message: '删除成功'
      }
    } else {
      ctx.body = {
        code: -1,
        message: '删除失败'
      }
    }
  }

  async searchAudit(){
      let {ctx,app}=this
      let data=await ctx.service.page.searchAudit()
      ctx.body=data
  }

}

module.exports = HomeController;